// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: 'ling-prod-7gcd7t0d5ffa0b3b'
})

const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()

  let dbName = event.dbName
  let param = event.param ? event.param : {}
  param.openid = wxContext.OPENID
  let flag = false
  
  await db.collection(dbName).add({ data: param }).then(res => {
    flag =  true
  }).catch(res=>{
    console.log("云函数add添加失败~~");
  })
  
  return flag

}